<?php

if (!isset($_SESSION)) {
    session_start();
}
require_once("connexion.php");
//var_dump($_POST);
if (isset($_POST['description']) && $_POST['description'] != '') {
    global $db;
    $date = new DateTime("NOW");
    $date = $date->format("Y-m-d");

    //Recherche de l'id de l'épisode en question
    $idEpisode = "SELECT idEpisode as timeline from episode where idSaison = $_POST[saison] and numeroEpisode = $_POST[episode]";
    $query = $db->query($idEpisode);
    $data = $query->fetch();
    $timeline = $data["timeline"];

    //insertion en base de la fiche perso
    $request = "INSERT INTO `fiche_personnage`"
            . "( `idPersonnage`, `idEpisode`, `idUser`, `description`, `statutVote`, `dateCreation`, `idSource`)"
            . " VALUES ($_POST[personnage] ,$timeline,$_SESSION[idUser],'$_POST[description]',0,'$date', 1)";
    $query = $db->query($request);
//var_dump($query);

    $idFiche = $db->lastInsertId();
    //Création du vote
    $request = "INSERT INTO `vote`"
            . "(`typeVote` , `idRepere`, `idFichePersonnage`, `idUser`, `dateVote`, `votePour`, `voteContre`)"
            . " VALUES (1 ,null ,$idFiche,$_SESSION[idUser],'$date',0, 0)";
    $query = $db->query($request);
//INSERT INTO `vote`(`typeVote`, `idRepere`, `idFichePersonnage`, `idUser`, `dateVote`, `votePour`, `voteContre`) VALUES (1 ,null ,1,1,0000-00-00,0, 0)
}
?>